class Solution:
    def reachingPoints(self, sx: int, sy: int, tx: int, ty: int) -> bool:
        # 处理完全一致的情况
        if sx == tx and sy == ty:
            return True

        # 处理终点坐标小于起点坐标的情况
        if tx < sx or ty < sy:
            return False

        # 令sx<=sy
        if sx > sy:
            sx, sy, tx, ty = sy, sx, ty, tx

        # 不断逆操作，看tx和ty能否转化为sx和sy
        while (sx <= tx and sy <= ty) and (sx < tx or sy < ty):
            # 令tx<=ty
            if tx > ty:
                tx, ty = ty, tx

            # 当ty是tx的倍数时
            if ty % tx == 0:
                if sx == tx:
                    return sy % sx == 0
                else:  # sx < tx
                    return False

            # 如果tx已经是sx的情况
            if sx == tx:
                return (ty - sy) % tx == 0

            # 将大的一直减到比小的小
            ty %= tx

            # 令tx<=ty
            if tx > ty:
                tx, ty = ty, tx

        return sx == tx and sy == ty


if __name__ == "__main__":
    print(Solution().reachingPoints(1, 1, 3, 5))  # True
    print(Solution().reachingPoints(1, 1, 2, 2))  # False
    print(Solution().reachingPoints(1, 1, 1, 1))  # True

    # 测试用例165/190
    print(Solution().reachingPoints(3, 3, 12, 9))  # True

    # 测试用例170/190
    print(Solution().reachingPoints(9, 10, 9, 19))  # True
